package com.sq.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.sq.common.utils.StringUtils;
import com.sq.system.mapper.SysUserRoleMapper;
import com.sq.system.pojo.SysUserRole;
import com.sq.system.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 *
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole>
    implements SysUserRoleService
{

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Override
    public Integer saveUserRole(List<String> roleIds, String userId) {

        if (Objects.isNull(roleIds) || roleIds.isEmpty()){
            return 0;
        }

        if (StringUtils.isBlank(userId)){
            return 0;
        }
        List<SysUserRole> sysUserRoles = new ArrayList<>();
        for (String roleId : roleIds){
            SysUserRole sysUserRole = new SysUserRole();
            sysUserRole.setRoleId(roleId);
            sysUserRole.setUserId(userId);
            sysUserRoles.add(sysUserRole);
        }
        boolean b = saveBatch(sysUserRoles);

        return b ? 1: 0;
    }
}




